package io.renren.modules.sys.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.entity.ColumnsInfoEntity;
import io.renren.modules.sys.service.ColumnsInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 列信息管理
 *
 * @author zhangfn
 * @date 2020-06-05 10:55:20
 */
@RestController
@RequestMapping("sys/columnsinfo")
public class ColumnsInfoController {
    @Autowired
    private ColumnsInfoService columnsInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:columnsinfo:list")
    public R list(@RequestParam Map<String, Object> params) {
        String tableid = (String) params.get("tableid");
        PageUtils page = null;
        if (null != tableid && tableid != "") {
            page = columnsInfoService.queryPage(params);
        }
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:columnsinfo:info")
    public R info(@PathVariable("id") Integer id) {
        ColumnsInfoEntity columnsInfo = columnsInfoService.getById(id);

        return R.ok().put("columnsInfo", columnsInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:columnsinfo:save")
    public R save(@RequestBody ColumnsInfoEntity columnsInfo) {
        columnsInfoService.save(columnsInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:columnsinfo:update")
    public R update(@RequestBody ColumnsInfoEntity columnsInfo) {
        ValidatorUtils.validateEntity(columnsInfo);
        columnsInfoService.updateById(columnsInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:columnsinfo:delete")
    public R delete(@RequestBody Integer[] ids) {
        columnsInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
